<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
	  <home></home>
	  
  </div>
  <template id="Home">
	  <div>
		  Home组件
		  <common-head @aaa="receive"></common-head>
      {{msg}}
	  </div>
  </template>
 
  <script src="./vue.js"></script>
  <script>
	  // 头部组件
	 const CommonHead = {
	
		template:`
			<div>
				我是头部组件
				<h2> {{title}} </h2>
				<button @click="triggerEvent">点击向父组件传递</button>
			</div>
		`,
		data () {
			return {
        msg: '我是子组件的数据'
			}
		},
		methods: {
			triggerEvent () {
        // 触发了一个自定义事件  事件名是 aaa
        this.$emit('aaa', this.msg)
      }
		}
	 }
    const Home = {
      template: '#Home',
      components: {
        CommonHead
      },
      data () {
        return {
          msg: 'aa'
        }
      },
      methods: {
        receive(msg){
          alert('over over 收到了一个数据时'+msg)
          this.msg = msg
        }
      }
    }
	Vue.component('Home',Home)
	
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>